@use 'github-markdown-css/github-markdown-light.css' as *;

.markdown-body {
  --o-gap-1: 4px;
  --o-gap-2: 8px;
  --o-gap-3: 12px;
  --o-gap-4: 16px;
  --o-gap-5: 24px;
  --o-gap-6: 32px;
  --o-gap-7: 40px;

  @include respond-to('<=laptop') {
    --o-gap-1: 4px;
    --o-gap-2: 8px;
    --o-gap-3: 8px;
    --o-gap-4: 12px;
    --o-gap-5: 16px;
    --o-gap-6: 24px;
    --o-gap-7: 24px;
  }

  @include respond-to('<=pad') {
    --o-gap-1: 4px;
    --o-gap-2: 8px;
    --o-gap-3: 8px;
    --o-gap-4: 8px;
    --o-gap-5: 12px;
    --o-gap-6: 16px;
    --o-gap-7: 16px;
  }

  @include respond-to('<=pad_v') {
    --o-gap-1: 4px;
    --o-gap-2: 8px;
    --o-gap-3: 8px;
    --o-gap-4: 8px;
    --o-gap-5: 12px;
    --o-gap-6: 16px;
    --o-gap-7: 16px;
  }

  @include respond-to('<=phone') {
    --o-gap-1: 4px;
    --o-gap-2: 8px;
    --o-gap-3: 12px;
    --o-gap-4: 16px;
    --o-gap-5: 24px;
    --o-gap-6: 28px;
    --o-gap-7: 12px;
  }
}

.markdown-body {
  color: var(--o-color-info2);
  font-family: inherit;
  min-height: auto;
  background-color: transparent;
  @include text1;

  div[class*='language-'] {
    position: relative;
    margin-top: var(--o-gap-5);
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    word-break: break-all;
    color: var(--o-color-info1);
    padding: 0;
    border: none;
  }

  h1 {
    @include h4;
    margin: 32px 0 12px;
  }

  h2 {
    @include text2;
    margin: 12px 0;
  }

  h3 {
    @include text1;
    margin: 12px 0;
  }

  h4 {
    @include text1;
    margin: 12px 0;
  }

  p {
    margin: 12px 0;

    & + p {
      margin: 8px 0;
    }
  }

  ul {
    list-style: disc;
  }

  ol > li:before {
    background-color: var(--o-color-ubmc);
    border-radius: 50%;
    //box-shadow: 0 0 0 4px var(--circle-bg, rgb(var(--o-mixedgray-1)));
    color: var(--o-color-info1-inverse);
    content: counter(num);
    display: inline-flex;
    justify-content: center;
    left: 0;
    @include tip2;
    height: 20px;
    line-height: 20px !important;
    position: absolute;
    top: 2px;
    width: 20px;
    z-index: 1;
  }

  ol > li:after {
    background-color: rgba(var(--o-mixedgray-14), 0.15);
    bottom: 1px;
    content: '';
    left: 10px;
    position: absolute;
    top: 10px;
    width: 1px;
  }

  ol {
    padding-left: 0;
    list-style: none !important;
    counter-reset: num;

    & > li {
      counter-increment: num;
      padding-left: 28px;
      position: relative;
      margin-top: 12px;

      ol {
        padding-left: 20px;
      }
    }
  }

  li {
    & > p {
      margin: 8px 0;
    }
  }

  hr {
    margin: 12px 0;
    height: 1px;
    border-bottom: 1px solid var(--o-color-control4);
    background-color: transparent;
  }

  a {
    --link-color: var(--o-color-ubmc);
    color: var(--link-color);
    --link-underline-x: 100%;
    background: linear-gradient(0deg, var(--link-color), var(--link-color))
    no-repeat var(--link-underline-x) bottom;
    background-size: 0 1px;
    transition: background-size var(--o-easing-standard) var(--o-duration-m2);
    &:hover {
      background-size: var(--link-underline-x) 1px;
      background-position-x: left;
      text-decoration: none;
    }
    &:focus, &:active {
      --link-color: var(--o-color-ubmc-focus);
    }
  }

  img {
    display: block;
    box-sizing: border-box;
  }

  pre {
    font-size: 100%;
    position: relative;
    padding: 0;
    background-color: var(--o-color-fill3);
    border-radius: var(--o-radius-m);
    overflow: hidden;
    margin-bottom: 8px;

    code {
      display: block;
      overflow-x: auto;
      padding: var(--o-gap-4);
      padding-top: 0;
      font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
    }
  }

  .md-table {
    overflow-x: auto;
    border-radius: var(--o-radius-s);
    margin-bottom: 12px;
    border: 1px solid var(--o-color-control4);
  }

  table {
    width: 100%;
    display: table;
    margin-bottom: 0;
    @include respond-to('<=laptop') {
      --table-head-cell-padding: 8px 16px;
    }

    @include respond-to('<=pad') {
      --table-head-cell-padding: 9px 12px;
    }

    @include respond-to('<=phone') {
      --table-head-cell-padding: 7px 12px;
    }


    thead {
      tr {
        border: none;

        th {
          padding-top: var(--o-gap-4);
          padding-bottom: var(--o-gap-4);
          padding-left: var(--o-gap-7);
          background-color: var(--o-color-control3-light);
          border: none;
          text-align: left;
          text-wrap: nowrap;

          &:first-child {
            border-radius: var(--table-radius) 0 0 0;
          }

          &:last-child {
            border-radius: 0 var(--table-radius) 0 0;
          }
        }
      }
    }

    tbody {
      tr {
        &:first-child {
          border: none;
        }

        &:last-child {
          td {
            &:last-child {
              border-radius: 0 0 var(--table-radius) 0;
            }

            &:first-child {
              border-radius: 0 0 0 var(--table-radius);
            }
          }
        }

        td {
          background-color: var(--o-color-fill2);
          padding-top: var(--o-gap-4);
          padding-bottom: var(--o-gap-4);
          padding-left: var(--o-gap-7);
          border: none;
          word-break: keep-all;
        }
      }
    }
  }

  .lang {
    display: none;
  }

  .vp-adaptive-theme {
    @include hover {
      .copy {
        opacity: 1;
      }
    }
  }

  .copy {
    display: none;
  }

  blockquote {
    color: var(--o-color-info3);
    border-color: var(--o-color-control1);
  }

  // 代码组
  .vp-code-group {
    pre {
      border-radius: 0 0 var(--o-radius-m) var(--o-radius-m);
    }

    .tabs {
      position: relative;
      display: flex;
      margin-right: -24px;
      margin-left: -24px;
      background-color: var(--o-color-control3-light);
      overflow-x: auto;
      overflow-y: hidden;
      border-radius: var(--o-radius-m) var(--o-radius-m) 0 0;
      height: 58px;
      padding: var(--o-gap-4) 0 0 var(--o-gap-5);
      @media (min-width: 640px) {
        margin-right: 0;
        margin-left: 0;
        border-radius: 8px 8px 0 0;
      }

      input {
        position: fixed;
        opacity: 0;
        pointer-events: none;
      }

      label {
        position: relative;
        display: inline-block;
        border-bottom: 1px solid transparent;
        margin-right: var(--o-gap-5);
        @include text2;
        font-weight: 500;
        white-space: nowrap;
        cursor: pointer;
        transition: color 0.25s;
        overflow: visible;

        &::after {
          position: absolute;
          bottom: -1px;
          right: 0px;
          left: 0px;
          z-index: 1;
          height: 2px;
          border-radius: 2px;
          content: '';
          transition: background-color 0.25s;
        }
      }


    }

    label:hover {
      color: var(--o-color-info1);
    }

    input:checked + label {
      color: var(--o-color-info1);
    }

    input:checked + label::after {
      background-color: var(--o-color-info1);
    }

    div[class*='language-'] {
      display: none;
      margin-top: 0 !important;
    }

    div[class*='language-'].active {
      display: block;
    }
  }


  // 代码块字体
  .hljs-emphasis {
    font-style: normal;
  }

  pre.mermaid {
    background-color: transparent;
  }

  div.mermaid {
    svg[aria-roledescription="error"] {
      display: none;
    }
  }

  .vp-code {
    &.shiki {
      span {
        color: var(--shiki-light, inherit);
      }
    }
    code {
      padding-bottom: 8px;
      .comment-line {
        font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica', 'Arial', sans-serif;
      }
    }
  }

  div[class*=language-] {
    margin-top: 0;
  }

  .mermaid {
    svg {
      display: block;
    }
  }

  .custom-block {
    padding: var(--o-gap-3) var(--o-gap-4);
    margin-bottom: var(--o-gap-3);
    border-radius: var(--o-radius-xs);
    @include text1;

    & + .custom-block {
      margin-top: 20px;
    }

    * {
      margin: 0;
    }

    .custom-block-title {
      display: flex;
      align-items: center;
      font-weight: 500;

      &::before {
        content: '';
        display: inline-block;
        width: 24px;
        height: 24px;
        background-size: 24px;
        background-repeat: no-repeat;
        margin-right: 8px;

        @include respond-to('laptop') {
          width: 20px;
          height: 20px;
          background-size: 20px;
        }

        @include respond-to('pad_h') {
          width: 18px;
          height: 18px;
          background-size: 18px;
          margin-right: 6px;
        }

        @include respond-to('pad_v') {
          width: 18px;
          height: 18px;
          background-size: 18px;
          margin-right: 4px;
        }

        @include respond-to('phone') {
          width: 16px;
          height: 16px;
          background-size: 16px;
          margin-right: 4px;
        }
      }
    }


    & > *:not(.custom-block-title) {
      margin-left: 48px;
      margin-bottom: 8px;
      position: relative;
      &::before {
        content: '';
        width: 6px;
        height: 6px;
        position: absolute;
        top: 8px;
        left: -14px;
        border-radius: 50%;
        background-color: var(--o-color-info2);
      }

      @include respond-to('laptop') {
        margin-left: 44px;
      }

      @include respond-to('pad_h') {
        margin-left: 40px;
      }

      @include respond-to('pad_v') {
        margin-left: 38px;
      }

      @include respond-to('phone') {
        margin-left: 36px;
      }

      &:last-child {
        margin-bottom: 0;
      }
    }

    code {
      border: 1px solid var(--o-color-control4);
    }

    &.note {
      background-color: rgb(var(--o-deepblue-1));

      .custom-block-title::before {
        background-image: url('@/assets/category/doc/icon-note.svg');
      }
    }

    &.warning {
      background-color: var(--o-color-warning4-light);

      .custom-block-title::before {
        background-image: url('@/assets/category/doc/icon-warn.svg');
      }
    }

    &.tip {
      background-color: var(--o-color-success4-light);

      .custom-block-title::before {
        background-image: url('@/assets/category/doc/icon-tip.svg');
      }
    }

    &.caution {
      background-color: var(--o-color-danger4-light);
      .custom-block-title::before {
        background-image: url('@/assets/category/doc/icon-caution.svg');
      }
    }

    &.important {
      background-color: rgb(232, 247, 252);
      .custom-block-title::before {
        background-image: url('@/assets/category/doc/icon-important.svg');
      }
    }
  }
}

[data-o-theme="dark"] {
  .markdown-body {
    .custom-block {
      &.important {
        background-color: rgb(0, 47, 76);
      }
    }
    .vp-code {
      &.shiki {
        span {
          color: var(--shiki-dark, inherit);
        }
      }
    }
  }
}
